<?php

/**
 * This is the model class for table "lab_term".
 *
 * The followings are the available columns in table 'lab_term':
 * @property integer $term_id
 * @property integer $start_week
 * @property integer $total_weeks
 * @property string $name
 * @property integer $status
 *
 * The followings are the available model relations:
 * @property LabSchedule[] $labSchedules
 * @property LabWeek $startWeek
 * @property LabWeek[] $labWeeks
 */
class Term extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Term the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'lab_term';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('start_week, total_weeks, name, status', 'required'),
			array('start_week, total_weeks, status', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('term_id, start_week, total_weeks, name, status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'Schedules' => array(self::HAS_MANY, 'Schedule', 'term_id'),
			'startWeek' => array(self::BELONGS_TO, 'Week', 'start_week'),
			'Weeks' => array(self::HAS_MANY, 'Week', 'term_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'term_id' => 'Term',
			'start_week' => 'Start Week',
			'total_weeks' => 'Total Weeks',
			'name' => 'Name',
			'status' => 'Status',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('term_id',$this->term_id);
		$criteria->compare('start_week',$this->start_week);
		$criteria->compare('total_weeks',$this->total_weeks);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('status',$this->status);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}